<?php
	require_once('bootstrap.php');
		
	$str = '<table id="gradient-style">';
	$str .= '<thead><tr>';
	//var_dump($_POST);
	//$_POST['sql_command'] = "select sum(decode(name,'free memory',bytes))/sum(bytes)*100 from v\$sgastat where pool='shared pool'";
	//$_POST['sql_command'] = "select * from dbstats";
	if(isset($_POST['sql_command']) && $_POST['sql_command'] != '') {
		global $db;
		
		$query = $db->db_query($_POST['sql_command']);
		$db->execute($query);
		$rs = array();
			
		while($row = oci_fetch_assoc($query)) {
			$rs[] = $row;
		}
		
		//var_dump($rs);
		
		if(sizeof($rs) < 1){
			$str .= "</tr></thead><tr><td>No result has been found</td></tr></table>";
			return $str;
		}
		
		foreach($rs as $data) {
			foreach($data as $key=>$value) {
				$str .= "<th scope=\"col\">$key</th>";
			}
			break;
		}
		
		$str .= '</tr></thead>';
		$str .= '<tbody>';
		foreach($rs as $data) {
			$str .= '<tr>';
			foreach($data as $key=>$value) {
				$str .= "<td>$value</th>";
			}
			$str .= '</tr>';
		}
		$str .= '</tbody></table>';

		echo $str;
	}
?>